package cn.fayang.ymcc.listener;

import cn.fayang.ymcc.domain.Blacklist;
import cn.fayang.ymcc.service.IBlacklistService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.List;


@WebListener//申明自定义的web监听器，被容器注册和使用
@Slf4j
public class PermissionScanListener implements ServletContextListener {
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    @Autowired
    private IBlacklistService blacklistService;


    /**
     *装载完成执行此方法
     * @param sce
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        new Thread(new Runnable() {
            /**
             * 防止容器装载时间太长开启异步线程
             */
            @Override
            public void run() {
                log.info("开启权限扫描");

                List<Blacklist> blacklist = blacklistService.selectList(null);


                log.info("结束权限扫描");
            }
        }).start();
    }
}
